<template>
  <div class="villageDisplay" v-loading="loading" >
    <el-row :gutter="10" v-if="secretaryList.length !== 0">
      <el-col :span="24">
        <el-card class="villageDisplay_content">
          <table class="villageDisplay_content_table">
            <tr v-for="item in secretaryList" :key="item.index">
              <td class="left_td">
                <div class="left">{{item.levelName}}</div>
              </td>
              <td class="right_td">
                <div class="row">
                  <div class="right_item" v-for="(subItem, index) in item.cadres" :key="index" :class="`${subItem.id == activeIndex ? 'active_style' : ''}`" @click="checkVillageDetail(subItem, subItem.id)">
                    <div class="village_avatar">
                      <div>
                        <img :src="subItem.headSculpture" alt="">
                      </div>
                    </div>
                    <div class="village_name">
                      <div>{{subItem.postName.replace("支部书记", "")}}</div>
                      <span>{{subItem.name}}</span>
                    </div>
                  </div>
                </div>
              </td>
            </tr>
          </table>
          <div style="min-width:400px; height:730px;">
          </div>
          <div class="village_detail" v-loading="checkVillageDetailLoading">
              <div class="village_header">
                <div v-if="JSON.stringify(avatar) !== '{}'" class="village_header_avatar">
                  <img :src="avatar.headSculpture">
                  <div class="village_detail_name">
                    <p>{{avatar.postName ? avatar.postName.replace("支部", "") : ''}}</p>
                    <span>{{villageDetail.name}}</span>
                  </div>
                </div>
                <div v-else class="village_header_avatar no_avatar">
                  暂无头像
                </div>
                <div class="village_header_detail">
                  <div class="detail_item">
                    <p>性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别</p>
                    <span>{{villageDetail.sex || '暂无'}}</span>
                  </div>
                  <div class="detail_item">
                    <p>出生日期</p>
                    <span>{{villageDetail.birth || '暂无'}}</span>
                  </div>
                  <div class="detail_item">
                    <p>民&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;族</p>
                    <span>{{villageDetail.nation || '暂无'}}</span>
                  </div>
                  <div class="detail_item">
                    <p>身份证号</p>
                    <span>{{villageDetail.identityCard || '暂无'}}</span>
                  </div>
                  <div class="detail_item">
                    <p>联系电话</p>
                    <span>{{villageDetail.contact || '暂无'}}</span>
                  </div>
                  <div class="detail_item">
                    <p>学&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;历</p>
                    <span>{{villageDetail.education || '暂无'}}</span>
                  </div>
                </div>
              </div>
              <div style="clear: both"></div>
                <div class="village_body">
                  <div class="age_limit">
                    <i></i>
                    <p>任职年限</p>
                    <span>{{villageDetail.onDutyTime ? villageDetail.onDutyTime + "年" : '暂无'}}</span>
                  </div>
                  <div class="capacity">
                    <i></i>
                    <p>能力研判</p>
                    <span>{{villageDetail.evaluation || '暂无'}}</span>
                  </div>
                  <div class="assess">
                    <i></i>
                    <p>考核情况</p>
                    <div v-if="villageDetail.kpiVillageStatisticsVOS" class="assess_table">
                      <div class="table_col_head">
                        <div class="table_row">年份</div>
                        <div class="table_row">分数</div>
                        <div class="table_row">全市排名</div>
                        <div class="table_row">等次</div>
                      </div>
                      <div class="table_col" v-for="item in villageDetail.kpiVillageStatisticsVOS" :key="item.index">
                        <div class="table_row">{{item.quotaYear || '暂无'}}</div>
                        <div class="table_row">{{item.score || '暂无'}}</div>
                        <div class="table_row">{{item.ranking || '暂无'}}</div>
                        <div class="table_row">{{item.partitionLevel || '暂无'}}</div>
                      </div>
                    </div>
                    <div style="font-size: 14px; text-align: center; margin-top: 8px" v-else>
                      暂无
                    </div>
                  </div>
                  <div class="commend">
                    <i></i>
                    <p>表彰情况</p>
                    <div class="comment_box" v-if="villageDetail.honours && villageDetail.honours.length !== 0">
                      <div class="commend_item" v-for="item in villageDetail.honours" :key="item.index">
                        <div class="detail_item">
                          <p>时&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;间</p>
                          <span>{{item.achieveTime || '暂无'}}</span>
                        </div>
                        <div class="detail_item">
                          <p>表彰级别</p>
                          <span>{{item.honourDescription || '暂无'}}</span>
                        </div>
                        <div class="detail_item">
                          <p>特殊表彰</p>
                          <span>{{item.honourType || '暂无'}}</span>
                        </div>
                        <div class="detail_item">
                          <p>奖惩内容</p>
                          <el-tooltip class="item" effect="dark" :content="item.content" placement="top-end">
                            <span>{{item.content}}</span>
                          </el-tooltip>
                        </div>
                        <div class="detail_item">
                          <p>佐证材料</p>
                          <el-popover
                              v-if="item.supportDoc"
                              placement="right"
                              width="330"
                              trigger="hover">
                              <div v-for="subItem in handleImage(item.supportDoc)" :key="subItem.index">
                                  <el-image :src="subItem"></el-image>
                              </div>
                              <el-button slot="reference" type="text">
                                <div class="el-icon-picture fileIcon"></div>
                              </el-button>
                          </el-popover>
                          <span v-else>暂无</span>
                        </div>
                      </div>
                    </div>
                    <div style="font-size: 14px; text-align: center; margin-top: 40px" v-else>
                      暂无
                    </div>
                  </div>
                </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

  </div>
</template>

<script>
export default {
  name: "village-secretary-display",
  data () {
    return {
      querylevel: '',
      secretaryList: [],
      loading: false,
      activeIndex: 0,
      avatar: {},
      villageDetail: {},
      checkVillageDetailLoading: false
    }
  },
  methods: {
      async getCadresGroup () {
          this.loading = true;
          let user = this.$store.state.userInfo;
          let path = '/identity/villageCadres/getCadresGroupByLevel';
          if (user.roleCode === 'TOWN_REVIEWER') {
            path += `?districtId=${user.districtId}`
          };
          const res = await this.$http('GET', path, false);
          this.secretaryList = res.reverse();
          this.loading = false
    },
    async checkVillageDetail(item, id) {
      this.checkVillageDetailLoading = true;
      this.avatar = {};
      this.villageDetail = {};
      this.avatar.headSculpture = item.headSculpture;
      this.avatar.postName = item.postName;
      this.activeIndex = id;
      const res = await this.$http('GET', `/identity/villageCadres/getLevelRelateInfo?cadresId=${id}`, false);
      this.villageDetail = res;
      setTimeout(_ => {
        this.checkVillageDetailLoading = false;
      }, 500)
    },
    handleImage(imageUrl){
        let arr = [];
        if(imageUrl){
            if(imageUrl.indexOf(',')>-1){
                imageUrl.split(',').forEach(item => {
                    arr.push(item.split('&')[0]);
                })
            }else{
                arr.push(imageUrl.split('&')[0]);
            }
        }
        return arr;
    },
  },
  mounted () {
    this.getCadresGroup();
  }
}
</script>

<style scoped lang="less">
.villageDisplay {
  min-height: 750px;
  .villageDisplay_content {
    min-height: 750px;
  }
  .villageDisplay_content_table{
    border-collapse: collapse; 
    max-width: 1200px;
  }
  .villageDisplay_content_table tr:last-child {
    border-bottom: none;
  }
  .left_td {
    padding: 0 !important;
    position: relative;
    width: 137px;
    background-color: #55BD94;
    border: 1px solid #fff;
  }
}
.el-card {
  padding-bottom: 35px;
  .el-card__body {
    overflow: hidden;
    height: 100%;
  }
}
.level {
  float: left;
  width: 137px;
  height: 510px;
  overflow: hidden;
  border-radius: 5px 0 0 5px;
  background-color: #fff;
}

.left {
  top: 0;
  left: 0;
  float: left;
  height: 80px;
  width: 144px;
  font-size: 20px;
  text-align: center;
  line-height: 80px;
  color:rgba(255,255,255,1);
  font-weight: 700;
}

.row {
  overflow: hidden;
  float: left;
}
.right_td {
  padding-top: 15px;
  margin-left: 15px;
  border-bottom: 1px dashed #DFDFDF;
}
.villageDisplay_content_table td {
  padding: 15px 0 0 0;
  padding-left: 14px;
}
.right_item {
  float: left;
  margin-right: 10px;
  padding-top: 0px;
  text-align: center;
  margin-bottom: 15px;
  color: #393939;
  width:120px;
  height:56px;  
  background: linear-gradient(180deg,rgba(255,255,255,1),rgba(247,247,249,1));
  border:1px solid rgba(237, 227, 226, 1);
  border-radius:4px;
  cursor: pointer;
  .village_avatar {
    float: left;
    margin: 12px 6px 0 8px;
    div {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      overflow: hidden;
    }
    img {
      width: 32px;
      height: 45px;
    }
  }
  .village_name {
    float: left;
    margin-top: 8px;
    text-align: left;
    div {
      height: 19px;
      font-size: 12px;
    }
    span {
      font-size: 14px;
    }
  }
}
.active_style {
  color: #fff;
  border: 1px solid #55BD94;
  background: url('../../../static/village-secretary-display/village-active.png') no-repeat;
}
.village-score {
  height: 525px;
}

.village_detail {
  position: fixed;
  top: 190px;
  right: 40px;
  padding: 22px;
  width:475px;
  height:730px;
  background:rgba(255,255,255,1);
  border:1px solid rgba(85, 189, 148, 1);
  border-radius:0px 4px 4px 0px;
  overflow: auto;
  .village_header_avatar {
    position: relative;
    float: left;
    width:130px;
    height:196px;
    border-radius:4px;
    overflow: hidden;
    img {
      width: 100%;
      height: 100%;
      border-radius:4px;
    }
    .village_detail_name {
      position: absolute;
      bottom: 0;
      left: 0;
      width:130px;
      height:40px;
      background:rgba(85,189,148,1);
      opacity: 0.9;
      border-radius:0px 0px 4px 4px;
      font-size: 12px;
      color: #fff;
      padding-top: 5px;
    }
  }
  .no_avatar {
    line-height: 196px;
    border-radius: 4px;
    background: #f5f7fa;
    color: #3A3A3A;
    font-size: 14px;
    border: 1px solid #ccc;
  }
  .village_header_detail {
    margin-left: 26px;
    float: left;
    .detail_item {
        text-align: left;
      p {
        float: left;
        font-size:12px;
        color:rgba(170,170,170,1);
        line-height:32px;
      }
      span {
        margin-left: 15px;
        font-size:12px;
        color:rgba(57,57,57,1);
        line-height:32px;
      }
    }
  }
  .village_body {
    margin-top: 27px;
    .age_limit,
    .capacity {
      text-align: left;
      height: 50px;
      line-height: 50px;
      border-top: 1px dashed #DFDFDF;
      p {
        display: inline-block;
        font-size: 14px;
        color:rgba(85,189,148,1);
        font-family:Microsoft YaHei UI;
      }
      span {
        font-size: 12px;
        margin-left: 20px;
      }
    }
    .age_limit,
    .capacity,
    .assess,
    .commend {
      >i {
          display: inline-block;
          width: 20px;
          height: 20px;
          vertical-align: middle;
        }
    }
    .age_limit {
      i {
        background: url("../../../static/village-secretary-display/age-limit-icon.png");
        background-size: contain;
      }
    }
    .capacity {
      i {
        background: url("../../../static/village-secretary-display/capacity-icon.png");
        background-size: contain;
      }
    }
    .assess {
      i {
        background: url("../../../static/village-secretary-display/assess_icon.png");
        background-size: contain;
      }
    }
    .commend {
      >i {
        background: url("../../../static/village-secretary-display/commend-icon.png");
        background-size: contain;
      }
    }
    .assess {
      padding: 15px 0;
      text-align: left;
      border-top: 1px dashed #DFDFDF;
      p {
        display: inline-block;
        font-size: 14px;
        color:rgba(85,189,148,1);
        font-family: Microsoft YaHei UI;
      }
      .assess_table {
        margin-top: 15px;
        .table_col,
        .table_col_head {
          display: flex;
          width:427px;
          height:33px;
          line-height: 33px;
          border-bottom: 1px solid #D8F2E8;
          .table_row {
            flex: 1;
            font-size: 14px;
            text-align: center;
          }
        }
        .table_col_head {
          background: #F1FFF9;
          color:rgba(170,170,170,1);
          border-bottom: 1px solid #B4EAD5;
        }
        .table_col {
          color: #393939;
          .table_row:last-child {
            color: #CC0000;
          }
        }
      }
    }
    .commend {
      padding-top: 15px;
      text-align: left;
      border-top: 1px dashed #DFDFDF;
      >p {
        display: inline-block;
        font-size: 14px;
        color:rgba(85,189,148,1);
        font-family:Microsoft YaHei UI;
      }
      .commend_item {
        display: flex;
        flex-wrap: wrap;
        padding: 10px 0;
        margin: 0 20px;
        border-top: 1px dashed #DFDFDF;
        .detail_item {
          width: 175px;
          height: 30px;
          line-height: 30px;
          text-align: left;
          .el-button {
            margin-top: -6px;
          }
          .fileIcon{
            font-size: 16px;
          }
          p {
            display: inline-block;
            width: 50px;
            font-size: 12px;
            color:rgba(170,170,170,1);
            vertical-align: top;
          }
          span {
            width: 100px;
            display: inline-block;
            margin-left: 15px;
            font-size: 12px;
            color:rgba(57,57,57,1);
            overflow:hidden;
            text-overflow:ellipsis;
            white-space:nowrap;
            vertical-align: middle;
          }
        }
      }
    }
    .commend_item:nth-child(1) {
      border-top: none!important;
    }
  }

}
</style>
<style>
  .village_detail::-webkit-scrollbar-thumb {
    background-color: #5EC79E!important;
  }
  .villageDisplay_content .el-card__body {
    padding: 0;
    display: flex;
  }
  .villageDisplay_content {
    border-radius: 8px;
  }
  
</style>
